#!/usr/bin/env python

"""Run setup.py command `pre_install` for all packages that have one."""

from os import chdir, path
import subprocess

from concurrent.futures import ProcessPoolExecutor
from os import chdir
from subprocess import check_call
from sys import argv

PACKAGES = [
    "contract_wrappers",
    "contract_addresses",
    "contract_artifacts",
    "json_schemas",
]

def run_cmd_on_package(package: str):
    """cd to the package dir, ./setup.py pre_install, cd .."""
    chdir(package)
    check_call(f"{path.join('.', 'setup.py')} pre_install".split())
    chdir("..")

ProcessPoolExecutor().map(run_cmd_on_package, PACKAGES)
